#ifndef __INTERACTION_H__
#define __INTERACTION_H__

#include "list.h"
#include "communication.h"
#include "communication_core.h"

/* 用于函数指针 */
enum func_options {
    USER_LOGIN = 0,
    USER_REGISTER,
    ADMIN_LOGIN,
    BUY_TICKET,
    RETURN_TICKET,
    MODIFY_USER,
    ADD_TICKET,
    DELETE_TICKET,
    MODIFY_TICKET,
    DELETE_USER,
    USER_MENU,
    MAIN_MENU,
    ADMIN_MENU,
    EXIT
};

#define FALSE_ (-1)

enum error {
    MALLOC_ERROR = 6,
    PARAM_ERROR
};

enum cue {
    NO_ERROR = 0,
    ID_NO_MATCH = 5,
    USER_REPEAT
};

struct interaction {
    struct list_head user_ticket_head, user_head, ticket_head;
    struct admin *admin;
};

typedef int (*func_t)(struct interaction *);

extern int user_login(struct data_packet data, int clientfd, struct interaction *interaction);
extern int user_register(struct data_packet data, int clientfd, struct interaction *interaction);
extern int flash_ticket(int clientfd, struct interaction *interaction);
extern struct list_head *find_ticket(struct data_packet data, int clientfd);
extern int get_ticket_from_py(struct data_packet data, int clientfd, char *ticket_buffer);
extern void send_ticket_to_app(char *ticket_buffer, int clientfd);
extern int buy_ticket(struct data_packet data, int clientfd, struct list_head *ticket_head, struct list_head *user_ticket_head, struct list_head *user_head);
extern int find_order(struct data_packet data, int clientfd, struct list_head *user_ticket_head, struct list_head *temporary_head);
extern int return_ticket(struct data_packet data, int clientfd, struct list_head *user_ticket_head, struct list_head *ticket_head);
extern void change_user(struct data_packet data, int clientfd, struct list_head *user_head);
extern void change_ticket(struct data_packet data, int clientfd, struct list_head *ticket_head, struct list_head *user_ticket_head);
extern void delete_user(struct data_packet data, int clientfd, struct list_head *user_head);
extern void delete_ticket(struct data_packet data, int clientfd, struct list_head *ticket_head, struct list_head *user_ticket_head);
extern void add_user(struct data_packet data, int clientfd, struct list_head *user_head);
extern void add_ticket(struct data_packet data, int clientfd, struct list_head *ticket_head);
extern int user_find_ticket(struct data_packet data, int clientfd, struct list_head *ticket_head, char *ticket_buffer);

#endif
